<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Manage Cars</title>
<?php
	include("Connection.php");
?>
<script>
	function gather_cars_by_location(val){
		var request = new XMLHttpRequest();
		request.onreadystatechange = function(){
			if(request.readyState == 4 && request.status == 200){
				$choose_car = document.getElementById("choose_car").innerHTML = request.responseText;
			}
		}
		request.open("GET", "manage_cars_populate.php?q="+val, true);
		request.send();
	}//end function gather_cars_by_location
</script>
</head>

<body>
<h1>Manage Cars</h1>

	<table width="100%">
    	<tr>
        	<td>
            	<h2><br />Add Car</h2><br>
          </td>
                      
            <td><h2>Change Car Location</h2>
            </td>
		</tr>
        
        <tr>
        	<td>
        		<form name="addCar" method='post' action='add_car.php'>
                	Vehicle Sno: <input type="text" name="v_sno"><br>
                    <br />
                    Car Model: <input type="text" name="car_model"><br>
                    <br />
                    
                     Car Type: 
                    <select name="car_type">
                    	<?php
							//query database for all car types
							$query = "SELECT Type FROM car GROUP BY Type;";									
							$result = mysql_query($query);
										
							while($row = mysql_fetch_assoc($result)){
    							echo '<option value="'.$row['Type'].'">'.$row[Type].'</option>';
							}
						?>
                    </select>
                    <br />
                    <br />
                    Location: 
                    <select name="car_location">
                    	<?php
							//query database for all car locations
							$query = "SELECT LocationName FROM location GROUP BY LocationName;";									
							$result = mysql_query($query);
										
							while($row = mysql_fetch_assoc($result)){
    							echo '<option value="'.$row['LocationName'].'">'.$row[LocationName].'</option>';
							}
						?>
                    </select><br /><br />
                    
                    Color: <input type="text" name="color"><br /><br />
                    
                    Hourly: <input type="text" name="hourly"><br /><br />
                    
                    Daily Rate: <input type="text" name="daily"><br /><br />
                    
                    Seating Capactiy: <input type="text" name="seating"><br /><br />
                    
                    Transmission Type: 
                    <select name="trans_type">
                    	<option value="automatic">Automatic</option>
                        <option value="manual">Manual</option>
                    </select><br /><br />xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                    
                    Bluetooth Connectivity: 
                    <select name="b_tooth">
                    	<option value="y">Yes</option>
                        <option value="n">No</option>
                    </select><br /><br />
                    
                    Auxillary Connectivity: 
                    <select name="aux">
                    	<option value="y">Yes</option>
                        <option value="n">No</option>
                    </select><br /><br />
                    
                    <input type="submit" value="Add">
                </form>
            </td>
            
            <td>
                <form name="change_car_loc" method='post' action='change_car_loc.php'>
                    Choose current location: 
                    <select name='curr_loc' id='curr_loc' onchange="gather_cars_by_location(this.value)">
                        <?php
                        	//query database for all car locations
                            $query = "SELECT LocationName FROM location GROUP BY LocationName;";										
                            $result = mysql_query($query);
                                            
                            while($row = mysql_fetch_assoc($result)){
                            	echo '<option value="'.$row['LocationName'].'">'.$row[LocationName].'</option>';
                            }
                        ?>
                    </select><br /><br />
                    
                    Choose Car: 
                    <select name="choose_car" id="choose_car">
                        <?php/*
                        	//displays all cars (car models) at selected location
							$selection = $_POST['curr_loc'];
                            $query = "SELECT CarModel FROM car WHERE CarLocation='$selection';";										
                            $result = mysql_query($query);
    
                            while($row = mysql_fetch_assoc($result)){
                            	echo '<option value="'.$row['CarModel'].'">'.$row[CarModel].'</option>';
                            }
							
							
							
							
							
							
                        */?>
                    </select>
                    <br /><br /><br />
               
               <hr /> 
               <h3>Brief Description</h3>
			
               Car Type: <input type="text" name="new_car_type"><br /><br />
               
               Color: <input type="text" name="new_car_color"><br /><br />
               
               Seating Capacity: <input type="text" name="new_seating_cap"><br /><br />
               
               Transmission Type: 
                    <select name="trans_type">
                    	<option value="automatic">Automatic</option>
                        <option value="manual">Manual</option>
                    </select><hr />
                    <br /><br />
                    
               Choose new location: 
                    <select name="curr_loc">
                        <?php
                        	//query database for all car locations
                            $query = "SELECT LocationName FROM location GROUP BY LocationName;";										
                            $result = mysql_query($query);
                                            
                            while($row = mysql_fetch_assoc($result)){
                            	echo '<option value="'.$row['LocationName'].'">'.$row[LocationName].'</option>';
                            }
                        ?>
                    </select><br /><br /><br /><br /><br />
				    <input type="submit" value="Submit Changes">       
               </form>
               
                             
            </td>
        </tr>
	</table>
</body>
</html>
